package com.jicheng.mapper;

import com.jicheng.dto.task.AttachmentDto;
import com.jicheng.dto.task.TemplateFileDto;
import com.jicheng.entity.TaskAttachment;

import com.jicheng.framework.mybatis.mapper.BaseMapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TaskAttachmentMapper extends BaseMapper<TaskAttachment> {

    @Delete("delete from tb_task_attachment where ${where} = #{id}")
    void delAll(@Param("where") String where, @Param("id") String id);

    @Delete("delete from tb_task_attachment where task_id = #{taskId} and attachment_id = #{attachmentId}")
    void del(@Param("taskId") String taskId,@Param("attachmentId") String attachmentId);

    @Select("select a.path file,a.name fileName,a.size size from tb_task_attachment ta ,tb_attachment a where ta.attachment_id = a.id and task_id = #{taskId}")
    List<AttachmentDto> getTaskAttachDetail(@Param("taskId") String taskId);

    @Select("select count(1) from tb_task_attachment where task_id = #{taskId} and attachment_id = #{attachmentId}")
    int isExist(@Param("taskId") String taskId,@Param("attachmentId") String attachmentId);
}
